const path = require('path');

const config = {
	projectName: 'taro-nutui-test',
	date: '2024-5-30',
	designWidth: 375,
	deviceRatio: {
		640: 2.34 / 2,
		750: 1,
		828: 1.81 / 2,
		375: 2 / 1,
	},
	sourceRoot: 'src',
	outputRoot: `dist/${process.env.TARO_ENV}`,
	alias: {
		'@': path.resolve(__dirname, '..', 'src'),
	},
	plugins: ['@tarojs/plugin-html'],
	defineConstants: {},
	scss: {
		resource: [path.resolve(__dirname, '..', 'src/assets/styles/custom_theme.scss')],
		// 默认京东 APP 10.0主题 > @import "@nutui/nutui-react-taro/dist/styles/variables.scss";
		data: `@import "@nutui/nutui-react-taro/dist/styles/variables.scss";`,
	},
	copy: {
		patterns: [],
		options: {},
	},
	framework: 'react',
	compiler: {
		type: 'webpack5',
		prebundle: { enable: false },
	},
	mini: {
		postcss: {
			pxtransform: {
				enable: true,
				config: {
					selectorBlackList: ['nut-'],
				},
			},
			url: {
				enable: true,
				config: {
					limit: 1024, // 设定转换尺寸上限
				},
			},
			cssModules: {
				enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
				config: {
					namingPattern: 'module', // 转换模式，取值为 global/module
					generateScopedName: '[name]__[local]___[hash:base64:5]',
				},
			},
		},
	},
	h5: {
		publicPath: '/',
		staticDirectory: 'static',
		// esnextModules: ['nutui-react'],
		postcss: {
			pxtransform: {
				enable: true,
				config: {
					selectorBlackList: ['nut-'],
				},
			},
			output: {
				filename: 'js/[name].[hash:8].js',
				chunkFilename: 'js/[name].[chunkhash:8].js',
			},
			miniCssExtractPluginOption: {
				ignoreOrder: true,
				filename: 'css/[name].[hash].css',
				chunkFilename: 'css/[name].[chunkhash].css',
			},
			autoprefixer: {
				enable: true,
				config: {},
			},
			cssModules: {
				enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
				config: {
					namingPattern: 'module', // 转换模式，取值为 global/module
					generateScopedName: '[name]__[local]___[hash:base64:5]',
				},
			},
		},
	},
	rn: {
		output: {
			ios: 'ios/main.jsbundle',
			iosAssetsDest: 'ios',
			android: 'android/index.android.bundle',
			androidAssetsDest: 'android'
		  },
	},
};

module.exports = function (merge) {
	if (process.env.NODE_ENV === 'development') {
		return merge({}, config, require('./dev'));
	}
	return merge({}, config, require('./prod'));
};
